import { reqC1, reqC2, reqC3 } from '@/api/product/attr';
import { defineStore } from 'pinia';
import type { CategoryResponseData, CategoryStoreState } from '@/api/product/attr/type';
let CategoryStore = defineStore('category', {
    state: (): CategoryStoreState => {
        return {
            category1List: [],
            category2List: [],
            category3List: [],
            // 一级分类id
            catId: '',
            // 二级分类id
            cat2Id: '',
            cat3Id: ''
        }
    },
    actions: {
        // 获取一级分类数据
        async getCategory1List() {
            let result: CategoryResponseData = await reqC1();
            console.log("获取一级分类数据: ", result);
            if (result.code === 200) {
                this.category1List = result.data;
            }
        },
        // 获取一级分类下二级分类数据(通过一级分类id)
        async getCategory2List() {
            let result: CategoryResponseData = await reqC2(this.catId);
            console.log("获取一级分类下二级分类数据: ", result);
            if (result.code === 200) {
                this.category2List = result.data;
            }
        },
        // 获取二级分类下三级分类数据(通过二级分类id)
        async getCategory3List() {
            let result: CategoryResponseData = await reqC3(this.cat2Id);
            if (result.code === 200) {
                this.category3List = result.data;
            }
        }
    }
})

export default CategoryStore;